package vip.xiaonuo.task;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import vip.xiaonuo.core.timer.TimerTaskRunner;
import vip.xiaonuo.modular.attendancegroup.entity.AttendanceGroup;
import vip.xiaonuo.modular.attendancegroup.service.AttendanceGroupService;
import vip.xiaonuo.modular.attendancerecord.service.AttendanceFlexSettlementService;

import javax.annotation.Resource;
import java.util.List;


@Component
@Slf4j
public class AttendanceFlexSettlementTask implements TimerTaskRunner {

    @Resource
    private AttendanceFlexSettlementService flexSettlementService;

    @Resource
    private AttendanceGroupService attendanceGroupService;

    @Override
    public void action(String jobParams, String taskId) {
        this.handleFlexTask();
    }

    @Override
    public void executeXxlJob() throws InterruptedException {
        this.handleFlexTask();
    }

    private void handleFlexTask(){
        List<AttendanceGroup> groups = attendanceGroupService.list(new LambdaQueryWrapper<AttendanceGroup>()
                .eq(AttendanceGroup :: getWorkDaysSource, 4)
                .eq(AttendanceGroup :: getUseStatus,0));


        for(AttendanceGroup group : groups){
            flexSettlementService.flexRecordSettlementByGroup(group);
        }


    }


}
